@include('admin.public.head')
@include('admin.public.laydate')

<style type="text/css">
    .ibox-title{
        float: left;
    }
    .class_base{
        position: relative;
        width: 70%;
        height: 200px;
        overflow-x: hidden;
        overflow-y: scroll;
        text-align: left;
        margin-bottom-bottom: 15px;
        float: left;
        margin-bottom: 15px;
        margin-top: 15px;
        font-size:14px
    }
    .class_base p{
        font-weight: bold;
    }
    .class_base p span{
        color:red;
    }
    .class_base::-webkit-scrollbar{
        display: none;
    }
    .span_c{
       padding-right: 20px;
    }
</style>

<div class="ibox-title">
    <h5>捆绑销售编辑</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">捆绑优惠名称：</label>
            <div class="col-sm-9">
                <input type="text" name="discount_name" class="form-control"  value="{{$result->discount_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">原價 ：</label>
            <div class="col-sm-9">
                <input type="number" name="original_price" class="form-control"  value="{{$result->original_price??'0'}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">優惠價：</label>
            <div class="col-sm-9">
                <input type="number" name="discount_price" class="form-control"  value="{{$result->discount_price??'0'}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">注意事项：</label>
            <div class="col-sm-9">
                <script id="points_attention" name="points_attention" type="text/plain" style="height:300px;">{!! $result->points_attention??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">圖片：</label>
            <div class="col-sm-9">
                <input type="file" name="cove" class="form-control"  value="{{$result->cove??''}}">
                <img src="{{$result->cove??''}}" width="300" height="150">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">視頻：</label>
            <div class="col-sm-9">
                <input type="file" name="video" class="form-control"  value="{{$result->video??''}}">
                @if(!empty($result->video)) @if($result->video != getDomain()."/") <embed src="{{$result->video??''}}" height="200" width="200"> @endif @endif
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">是否啓用：</label>
            <div class="col-sm-9">
                <label class="radio-inline">
                    <input type="radio" @if(isset($result->is_enable)) @if($result->is_enable == 1) checked
                           @endif @endif value="1" name="is_enable">是</label>
                <label class="radio-inline">
                    <input type="radio" @if(isset($result->is_enable)) @if($result->is_enable == -1) checked
                           @endif @endif value="-1" name="is_enable">否</label>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">课程安排：</label>
            <div class="col-sm-9 class_base">
                @foreach($reservation_lists as $k=>$v)
                    <p>
                        <input type="checkbox" class="" name="class_base_info_id" value="{{$v['id']}}" @if(isset($class_info_id)) @if(in_array($v['id'], $class_info_id)) checked @endif @endif>&nbsp;&nbsp;
                        <span>課室</span>：<em class="span_c">{{$v['classsroom']['numbering']}}</em><span>教師</span>：<em class="span_c">{{$v['teacher']['teacher_name']}}</em><span>課程</span>：<em class="span_c">{{$v['class_base']['class_name']}}</em><span>周期</span>：<em class="span_c">{{$v['class_week']}}</em><span>時段</span>：<em class="span_c">{{$v['class_time']['time_start']}}~{{$v['class_time']['time_end']}}</em><span>季節</span>：<em class="span_c">{{$v['quarterly']['name']}}</em>
                    </p>
                @endforeach
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">有效期（天）：</label>
            <div class="col-sm-9">
                <input type="number" value="{{$result->meal_day??''}}" class="form-control"
                       name="meal_day" autocomplete="off">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/binding" class="btn btn-primary" >返回捆绑销售列表</a>
            </div>
        </div>
    </form>
</div>
<script>

    var points_attention_content = UE.getEditor('points_attention');


    $('.do').click(function(){

        var form = new FormData();

        var id = $('input[name="id"]').val();

        var discount_name = $('input[name="discount_name"]').val();
        var original_price = $('input[name="original_price"]').val();
        var discount_price = $('input[name="discount_price"]').val();
        var is_enable = $('input[name="is_enable"]:checked').val();
        var meal_day = $('input[name="meal_day"]').val();
        var points_attention =points_attention_content.getContent();
        var cove = $('input[name="cove"]')[0].files[0];
        var video = $('input[name="video"]')[0].files[0];

        var class_base_info_id = new Array();

        if(meal_day == ''){
            var swal_json = {
                title: '有效天數不能為空',
                type: "error"
            }

            swal(swal_json, function (isConfirm) {

            });

            return false;
        }

        if(parseInt(meal_day) == 0 || parseInt(meal_day) < 0){
            var swal_json = {
                title: '不能為0或者小於0',
                type: "error"
            }

            swal(swal_json, function (isConfirm) {

            });

            return false;
        }

        $('input[name="class_base_info_id"]:checked').each(function(){
            class_base_info_id.push($(this).val());
        });

        form.append("cove", cove);
        form.append("video", video);
        form.append("id", id);
        form.append("discount_name", discount_name);
        form.append("is_enable", is_enable);
        form.append("original_price", original_price);
        form.append("meal_day", meal_day);
        form.append("discount_price", discount_price);
        form.append("points_attention", points_attention);
        form.append("class_base_info_id", class_base_info_id);

        $.ajax({
            type: 'POST',
            url: '/binding_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){
                console.log(data);
                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;

    });
</script>
